package com.gpio;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * @author lotey
 * @date 2017年2月27日 下午3:38:14
 * @desc 读取设备映射文件到map内存中
 */
public class EquipmentConstant {
	
	private static Logger logger = LogManager.getLogger(EquipmentConstant.class);
	
	public static Map<String, Integer> equipmentMap = null;
	
	static {
        equipmentMap = new HashMap<String, Integer>();
		try {
			// 获得资源包  
//		    ResourceBundle rb = ResourceBundle.getBundle("equ_mapping");
			InputStream inputStream = new FileInputStream(new File("/home/pi/mqserver/equ_mapping.properties"));
		    ResourceBundle rb = new PropertyResourceBundle(inputStream);
		    // 通过资源包拿到所有的key  
		    Enumeration<String> allKey = rb.getKeys();  
		    String key = null;
		    String value = null;
		    while (allKey.hasMoreElements()) {  
		        key = allKey.nextElement();  
		        value = (String) rb.getString(key);  
				equipmentMap.put(key, Integer.decode(value.replaceAll("\\s*","")));
		    }  
		} catch (Exception e) {
			logger.error("================请检查/home/pi/mqserver目录下是否存在equ_mapping.properties文件================");
			e.printStackTrace();
		}
    }
	
	public static void main(String[] args) {
		System.out.println(equipmentMap.get("1234566"));
		System.out.println(65535>>8);
	}

}
